/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.areaDataAll.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.annotation.rest.AnonymousGetMapping;
import com.fzhucc.modules.areaDataAll.domain.AreaDataAll;
import com.fzhucc.modules.areaDataAll.domain.dto.AreaDataAllQueryCriteria2;
import com.fzhucc.modules.areaDataAll.service.AreaDataAllService;
import com.fzhucc.modules.areaDataAll.domain.dto.AreaDataAllQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.text.ParseException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2024-04-01
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "福州市大屏数据导出管理")
@RequestMapping("/api/areaDataAll")
public class AreaDataAllController {

    private final AreaDataAllService areaDataAllService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('areaDataAll:list')")
    public void exportAreaDataAll(HttpServletResponse response, AreaDataAllQueryCriteria criteria) throws IOException {
        areaDataAllService.download(areaDataAllService.queryAll(criteria), response);
    }

    @Log("导出数据根据时间计算值")
    @ApiOperation("导出数据根据时间计算值")
    @AnonymousGetMapping(value = "/downloadByDay")
    //@PreAuthorize("@el.check('areaDataAll:list')")
    public void downloadByDay(HttpServletResponse response, AreaDataAllQueryCriteria2 criteria) throws IOException, ParseException {
        areaDataAllService.downloadByDay(areaDataAllService.queryAllByDayData(criteria), response);
    }

    @GetMapping
    @Log("查询福州市大屏数据导出")
    @ApiOperation("查询福州市大屏数据导出")
    @PreAuthorize("@el.check('areaDataAll:list')")
    public ResponseEntity<Object> queryAreaDataAll(AreaDataAllQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(areaDataAllService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    /*@PostMapping
    @Log("新增福州市大屏数据导出")
    @ApiOperation("新增福州市大屏数据导出")
    @PreAuthorize("@el.check('areaDataAll:add')")
    public ResponseEntity<Object> createAreaDataAll(@Validated @RequestBody AreaDataAll resources){
        return new ResponseEntity<>(areaDataAllService.create(resources), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改福州市大屏数据导出")
    @ApiOperation("修改福州市大屏数据导出")
    @PreAuthorize("@el.check('areaDataAll:edit')")
    public ResponseEntity<Object> updateAreaDataAll(@Validated @RequestBody AreaDataAll resources){
        areaDataAllService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除福州市大屏数据导出")
    @ApiOperation("删除福州市大屏数据导出")
    @PreAuthorize("@el.check('areaDataAll:del')")
    public ResponseEntity<Object> deleteAreaDataAll(@RequestBody Integer[] ids) {
        areaDataAllService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }*/
}